package com.doudou.eurekaConsumer.consumer;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

/**
 * @author mazh
 * @date 2021-12-02 22:23
 */
@RestController
public class ConsumerController {
    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "fallback")
    @GetMapping("/consumer")
    public String consumer(@RequestParam Map<String, Object> params){
        return restTemplate.getForEntity("http://EUREKAPROVIDER/hello?name=" + params.get("name"),String.class).getBody();
    }
    public String fallback(Map<String, Object> params){
        return "fallback,请稍后重试！";
    }
}
